
class wilddogService {
    userGroup: string[];
    resLogin: any;
    /**询价野狗数据 */
    refInquiryArr: string[] = [];
    /**报表导出野狗数据 */
    refExcelArr: string[] = [];
    strInquiryClick: Array<number> = [];
    strClick: number[] = [];
    fInquiry: number;
    f: number;
    /**发货单野狗数据 */
    refOrderArr: string[] = [];
    tagType: number[] = [];
    /**
     * 野狗地址
     */
    wilddogUrl: string;
    /**
     * 评价消息
     */
    refEvaluat: string;
    /**
    * 消息通知
    */
    refEvaluateShipOrder: string;
    /**报表导出野狗消息存储 */
    refExcel: string;
    constructor(private rootScope: ng.IRootScopeService, private $wilddogObject: any, private $wilddogArray: any, private routeService: routeService) {


        this.wilddogUrl = this.routeService.getWilddogUrl();
        // this.rootScope.$watch(function () { return window.localStorage.getItem("loginData") }, this.refValue);
        this.refValue()
    }


    localStorageloginData = () => {
        return window.localStorage.getItem("loginData");
    }

    /**
     * 异步导出
     */
    exportExcel = () => {

    }

    /**
     * 询价
     */
    inquiry = () => {
        this.strInquiryClick.push(Date.now());

        // ['1','0','2','4'].forEach(item=>{
        //     let scopeName: string = 'refInquiry' + item;

        //         const scopeValue = window.localStorage.getItem(scopeName);
        //         this.rootScope[scopeName] = JSON.parse(scopeValue)
              
        //         this.rootScope.$watch(scopeName, (newValue, oldValue) => {
        //             let myDate = new Date();
        //             this.strInquiryClick.push(myDate.getTime());//毫秒
        //             while (this.strInquiryClick.length > 2) { this.strInquiryClick.shift(); }
        //             //console.info('时间数组Inquiry', strInquiryClick);
        //             switch (this.strInquiryClick.length) { case 2: this.fInquiry = this.strInquiryClick[1] - this.strInquiryClick[0]; break; }
        //             //console.info('时间间隔Inquiry', fInquiry);
        //             if (this.fInquiry >= 10000) {
        //                 this.rootScope.$broadcast('WildDog:Inquiry' + item, newValue);
        //             }
        //         });
        // })
        // if (localStorage.getItem('refInquiry')) {
        //     this.refInquiryArr = localStorage.getItem('refInquiry').split(",");
        //     this.refInquiryArr.forEach((item, index) => {
        //         let last: string = item.split("/")[(item.split("/").length) - 1];
        //         let scopeName: string = 'refInquiry' + last;

        //         const scopeValue = window.localStorage.getItem(scopeName);
        //         this.rootScope[scopeName] = JSON.parse(scopeValue)
              
        //         this.rootScope.$watch(scopeName + ".$value", (newValue, oldValue) => {
        //             let myDate = new Date();
        //             this.strInquiryClick.push(myDate.getTime());//毫秒
        //             while (this.strInquiryClick.length > 2) { this.strInquiryClick.shift(); }
        //             //console.info('时间数组Inquiry', strInquiryClick);
        //             switch (this.strInquiryClick.length) { case 2: this.fInquiry = this.strInquiryClick[1] - this.strInquiryClick[0]; break; }
        //             //console.info('时间间隔Inquiry', fInquiry);
        //             if (this.fInquiry >= 10000) {
        //                 this.rootScope.$broadcast('WildDog:Inquiry' + last, newValue);
        //             }
        //         });
        //     })
        // }
    }

    /**
     * 订单
     */
    order = () => {
        // ['21','12','11','13','15','22'].forEach(item=>{
        //     let scopeName = 'refOrder' + item;

        //     const scopeValue = window.localStorage.getItem(scopeName);
        //     this.rootScope[scopeName] = JSON.parse(scopeValue)
            
        //     this.rootScope.$watch(scopeName , (newValue, oldValue) => {
        //         let myDate = new Date();
        //         this.strClick.push(myDate.getTime());//毫秒
        //         while (this.strClick.length > 2) { this.strClick.shift(); }
        //         //console.info('时间数组Order', this.strClick);
        //         switch (this.strClick.length) { case 2: this.f = this.strClick[1] - this.strClick[0]; break; }
        //         //console.info('时间间隔Order', f);
        //         if (this.f >= 10000) {
        //             this.rootScope.$broadcast('WildDog:Order' + item, newValue);
        //         }
        //     });
        // })

        
        // if (localStorage.getItem('refOrder')) {
        //     this.refOrderArr = localStorage.getItem('refOrder').split(",");
        //     //订单
        //     this.refOrderArr.forEach((item, index) => {
        //         let last = item.split("/")[(item.split("/").length) - 1];
        //         let scopeName = 'refOrder' + last;

        //         const scopeValue = window.localStorage.getItem(scopeName);
        //         this.rootScope[scopeName] = JSON.parse(scopeValue)
               
        //         this.rootScope.$watch(scopeName , (newValue, oldValue) => {
        //             let myDate = new Date();
        //             this.strClick.push(myDate.getTime());//毫秒
        //             while (this.strClick.length > 2) { this.strClick.shift(); }
        //             //console.info('时间数组Order', this.strClick);
        //             switch (this.strClick.length) { case 2: this.f = this.strClick[1] - this.strClick[0]; break; }
        //             //console.info('时间间隔Order', f);
        //             if (this.f >= 10000) {
        //                 this.rootScope.$broadcast('WildDog:Order' + last, newValue);
        //             }
        //         });
        //     });
        // }

    }

    /**左侧导航野狗数字--refOrder11*/
    refValue = () => {
        if (window.localStorage.getItem("loginData")) {
            this.resLogin = JSON.parse(window.localStorage.getItem("loginData"));
            this.refEvaluat = this.wilddogUrl + this.resLogin.id + "/" + 1 + "/" + 1;
            this.refEvaluateShipOrder = this.wilddogUrl + this.resLogin.id + "/" + 1 + "/" + 0;
            /**报表导出野狗消息存储 */
            // this.refExcel = new Wilddog(this.wilddogUrl + this.resLogin.id + "/" + 2);

            this.userGroup = this.resLogin.commissionerType;
            this.refOrderArr = [];
            this.refInquiryArr = [];
            
            window.localStorage.setItem('refExcel',this.refExcel);
            this.userGroup.forEach((item, index) => {
                switch (item) {
                    /**0-10询价单，11-15订单 */
                    case '调度专员': this.tagType = [0, 11]; break;
                    case '计划专员': this.tagType = [1, 12, 22, 21]; break;
                    case '调度经理': this.tagType = [2, 13]; break;
                    case '商务专员': this.tagType = [4]; break;
                    case '客服专员': this.tagType = [15]; break;
                    default: return false;
                }

                this.tagType.forEach((subItem, subIndex) => {
                    if (subItem >= 11 || subItem == 21) {
                        this.refOrderArr.push(this.wilddogUrl + this.resLogin.id + "/" + 0 + "/" + subItem);
                    } else if (subItem <= 4 || subItem == 22) {
                        this.refInquiryArr.push(this.wilddogUrl + this.resLogin.id + "/" + 0 + "/" + subItem);
                    }
                });
                window.localStorage.setItem('refInquiry', this.refInquiryArr.join(","));
                window.localStorage.setItem('refOrder', this.refOrderArr.join(","));
            });

            window.localStorage.setItem('refEvaluate', this.refEvaluat);

            window.localStorage.setItem('refEvaluateShipOrder', this.refEvaluateShipOrder);

            this.inquiry();

            this.order();
            // if (localStorage.getItem('refEvaluateShipOrder')) {
            //     this.rootScope["dataArr"] = [localStorage.getItem('refEvaluate')].concat(localStorage.getItem('refEvaluateShipOrder'));
            // } else {
            //     this.rootScope["dataArr"] = (localStorage.getItem('refEvaluate'));
            // }

        }
    }

}
angular.module('wilddogService', []).service("wilddogService", ["$rootScope", "$wilddogObject", "$wilddogArray", "routeService", wilddogService]);

